<%layout("/common/_layout.html"){ %>
<script type="text/javascript">

function changeStatus(url,id,targetStatus) {
    
    $.ajax({
        url : url,
        data : {"id":id,"target_status":targetStatus},
        dataType : "json",
        async : true,
        success : function(data) {
            //parent.swal({title: "配置成功!", text: data.message, type: "success",timer: 2000,   showConfirmButton: false});
            parent.layer.msg("配置: " + data.message);
        }
        
    });
    
}
 
$(function(){
    var $mycheckbox = $('.switch-button').find("input[type='checkbox']");
    $mycheckbox.each(function(){
        var myid = $(this).attr("id");
        $("#"+myid).on({
            'switchChange.bootstrapSwitch': function(event, state) {
              var id =$(this).attr("id") ;
              console.log("switch:"+id+":"+state);
              changeStatus("${base}/sku/changeStatus",id,state?1:0);
            }
        });
    });

  });
  
 
</script>

<%#ajax userTable:{%>
<div class="am-cf am-padding">
  <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg">商品管理</strong>
    /
    <small>Sku管理</small>
  </div>
</div>
<form class="am-form" id="list-form" action="${base}/sku/list" method="post">
  <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
  <div class="am-g">
    <div class="am-u-sm-12 am-u-md-6" style="padding:0px 1.6rem 1.6rem 1rem;margin-left:10px;">
      <div class="am-btn-toolbar">
        <div class="am-btn-group am-btn-group-xs" >
          <%if(so.hasPermission("SKU_ADD")) {%>
          <button type="button" class="am-btn am-btn-default" onclick="location.href='${base}/sku/add'">
            <span class="am-icon-plus"></span>
            新增Sku属性
          </button>
          <%}%>
          <!--<%if(so.hasPermission("SKU_DELETE")) {%>
          <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default" onclick="deleteAll('${base}/sku/delete')">
            <span class="am-icon-trash-o"></span>
            删除
          </button>
          <%}%>--></div>
      </div>
    </div>
    <div class="am-u-sm-12 am-u-md-3" >
      <div class="am-input-group am-input-group-sm">
        <input type="text" class="am-form-field" id="name" value="${name!}" placeholder="按Sku名称或者属性可选项搜索"/>
        <span class="am-input-group-btn">
          <button id="submit-btn" class="am-btn am-btn-default" type="button">搜索</button>
        </span>
      </div>
    </div>
  </div>
</form>

<div class="am-g">
  <div class="am-u-sm-12">
    <div class="am-scrollable-horizontal">
      <table class="am-table am-table-striped am-table-hover table-main">
        <thead>
          <tr class="am-text-nowrap">
            <!--<th class="table-check">
            <input type="checkbox"  id="allCheck"/>
          </th>
          -->
          <th class="table-title">名称</th>
          <!--<th class="table-title">代码</th>
        -->
        <th class="table-title">可用属性值</th>
        <th class="table-title">排序</th>
        <th class="table-title">编辑者</th>
        <th class="table-title">编辑时间</th>
        <!--<th class="table-title">是否可用</th>
      -->
      <th class="table-title">操作</th>
    </tr>
  </thead>
  <tbody>
    <%for(item in pager.list!){%>
    <tr>
      <!--<td>
      <input type="checkbox" name="ids" value="${item.id}"></td>
    -->
    <td>${item.name}</td>
    <!--<td>${item.code}</td>
  -->
  <td>
    <%if(so.hasPermission("SKU_LISTOPT")) {%>
    <a href="${base}/sku/listOpt/${item.id}">${item.optNames}</a>
    <%}else if("尚未有属性值，请点击点击添加..."!=item.optNames){%>
    ${item.optNames}
    <%}%></td>
  <td>${item.sort}</td>
  <td>${item.operated_by}</td>
  <td>${item.operated_time}</td>

  <!--<td>
  <div class="switch-button">
    <input id="${item.id}"  type="checkbox" data-size='xs' data-am-switch  data-off-text="禁用" data-on-text="可用"  
                        <%if(item.enabled==1){%>
    checked
    <%}else{%>
    <%}%>/></div>
</td>
-->
<td>
  <div class="am-btn-toolbar">
    <div class="am-btn-group am-btn-group-xs">
      <%if(so.hasPermission("SKU_EDIT")) {%>
      <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="location.href='${base}/sku/edit?id=${item.id}'">
        <span class="am-icon-pencil-square-o"></span>
        编辑
      </button>
      <%}%></div>
  </div>
</td>

</tr>
<%}%></tbody>
</table>
</div>

<div class="am-cf">
<!-- 分页 -->
<%if (pager.list.~size >
0){%>
<div class="am-fr">
<% include("/admin/common_pager.tpl"){}%></div>
<%}else{%>
<div class="am-kai">
<h3>没有找到任何记录!</h3>
</div>
<%}%></div>

</div>
</div>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="modal">
<div class="am-modal-dialog">
<div class="am-modal-hd"> <i class="am-icon-refresh am-icon-spin"></i>
<a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
</div>
<div class="am-modal-bd">正在处理，请稍等...</div>
</div>
</div>

<script type="text/javascript">
    $(function(){
      var keywordsObj = {};
      $("#submit-btn").on("click",function(){
        if($("#name").val())
          keywordsObj.name = $("#name").val();
             
        var keywords = "";
        if(!$.isEmptyObject(keywordsObj)){
          keywords = JSON.stringify(keywordsObj);
        }
        console.log("keywords = "+ keywords);

        $("#keywords").val(keywords);
        $("#list-form").submit();
      });
    });
 
  </script>
<%}%>
<%}%>